package com.ruoyi.aitcommon.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;

import cn.hutool.core.util.StrUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.aitcommon.mapper.AitLogMapper;
import com.ruoyi.aitcommon.domain.AitLog;
import com.ruoyi.aitcommon.service.IAitLogService;
import com.ruoyi.aitcommon.utils.AITConst;

/**
 * 接口日志Service业务层处理
 * 
 * @author cli
 * @date 2021-06-19
 */
@Service
public class AitLogServiceImpl implements IAitLogService 
{
    @Autowired
    private AitLogMapper aitLogMapper;

    /**
     * 查询接口日志
     * 
     * @param id 接口日志ID
     * @return 接口日志
     */
    @Override
    public AitLog selectAitLogById(Long id)
    {
        return aitLogMapper.selectAitLogById(id);
    }

    /**
     * 查询接口日志列表
     * 
     * @param aitLog 接口日志
     * @return 接口日志
     */
    @Override
    public List<AitLog> selectAitLogList(AitLog aitLog)
    {
        return aitLogMapper.selectAitLogList(aitLog);
    }

    /**
     * 新增接口日志
     * 
     * @param aitLog 接口日志
     * @return 结果
     */
    @Override
    public int insertAitLog(AitLog aitLog)
    {
//    	截取字段长度
        aitLog.setCreateTime(DateUtils.getNowDate());
        aitLog.setOperUrl(StrUtil.subWithLength(aitLog.getOperUrl(),0,AITConst.STRINGSIZE));
        aitLog.setInParam(StrUtil.subWithLength(aitLog.getInParam(), 0, AITConst.BIGSTRINGSIZE));
        aitLog.setRetParam(StrUtil.subWithLength(aitLog.getRetParam(), 0, AITConst.BIGSTRINGSIZE));
        aitLog.setRetmsg(StrUtil.subWithLength(aitLog.getRetmsg(), 0, AITConst.BIGSTRINGSIZE));

        aitLog.setParField0(StrUtil.subWithLength(aitLog.getParField0(),0,AITConst.STRINGSIZE));
        aitLog.setParField1(StrUtil.subWithLength(aitLog.getParField1(),0,AITConst.STRINGSIZE));
        aitLog.setParField2(StrUtil.subWithLength(aitLog.getParField2(),0,AITConst.STRINGSIZE));
        aitLog.setParField3(StrUtil.subWithLength(aitLog.getParField3(),0,AITConst.STRINGSIZE));
        aitLog.setParField4(StrUtil.subWithLength(aitLog.getParField4(),0,AITConst.STRINGSIZE));
        aitLog.setParField5(StrUtil.subWithLength(aitLog.getParField5(),0,AITConst.STRINGSIZE));
        aitLog.setParField6(StrUtil.subWithLength(aitLog.getParField6(),0,AITConst.STRINGSIZE));
        aitLog.setParField7(StrUtil.subWithLength(aitLog.getParField7(),0,AITConst.STRINGSIZE));
        aitLog.setParField8(StrUtil.subWithLength(aitLog.getParField8(),0,AITConst.STRINGSIZE));
        aitLog.setParField9(StrUtil.subWithLength(aitLog.getParField9(),0,AITConst.STRINGSIZE));

        aitLog.setRetField0(StrUtil.subWithLength(aitLog.getRetField0(),0,AITConst.STRINGSIZE));
        aitLog.setRetField1(StrUtil.subWithLength(aitLog.getRetField1(),0,AITConst.STRINGSIZE));
        aitLog.setRetField2(StrUtil.subWithLength(aitLog.getRetField2(),0,AITConst.STRINGSIZE));
        aitLog.setRetField3(StrUtil.subWithLength(aitLog.getRetField3(),0,AITConst.STRINGSIZE));
        aitLog.setRetField4(StrUtil.subWithLength(aitLog.getRetField4(),0,AITConst.STRINGSIZE));
        aitLog.setRetField5(StrUtil.subWithLength(aitLog.getRetField5(),0,AITConst.STRINGSIZE));
        aitLog.setRetField6(StrUtil.subWithLength(aitLog.getRetField6(),0,AITConst.STRINGSIZE));
        aitLog.setRetField7(StrUtil.subWithLength(aitLog.getRetField7(),0,AITConst.STRINGSIZE));
        aitLog.setRetField8(StrUtil.subWithLength(aitLog.getRetField8(),0,AITConst.STRINGSIZE));
        aitLog.setRetField9(StrUtil.subWithLength(aitLog.getRetField9(),0,AITConst.STRINGSIZE));
        
//        设置默认值
        aitLog.setCreateTime(DateUtils.getNowDate());
        return aitLogMapper.insertAitLog(aitLog);
    }

    /**
     * 修改接口日志
     * 
     * @param aitLog 接口日志
     * @return 结果
     */
    @Override
    public int updateAitLog(AitLog aitLog)
    {
        aitLog.setUpdateTime(DateUtils.getNowDate());
        return aitLogMapper.updateAitLog(aitLog);
    }

    /**
     * 批量删除接口日志
     * 
     * @param ids 需要删除的接口日志ID
     * @return 结果
     */
    @Override
    public int deleteAitLogByIds(Long[] ids)
    {
        return aitLogMapper.deleteAitLogByIds(ids);
    }

    /**
     * 删除接口日志信息
     * 
     * @param id 接口日志ID
     * @return 结果
     */
    @Override
    public int deleteAitLogById(Long id)
    {
        return aitLogMapper.deleteAitLogById(id);
    }
}
